﻿using ClinicSystem.configure;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ClinicSystem.UserCon
{
    public partial class Search : UserControl
    {
        public  EventHandler ComboBoxTextChanged;
        public List<string> peopleInfo = new List<string>();
        public List<string> medicineList=new List<string>();
        public List<string> dosageList = new List<string>();
        public List<string> number = new List<string>();
        public Search()
        {
            InitializeComponent();
        }

        private void button_query_Click(object sender, EventArgs e)
        {
            string colname =textBox_name.Text.Trim();
            List<string> peoplelist = new List<string>();
            List<string> datelist = new List<string>();
            if (!string.IsNullOrEmpty(textBox_name.Text))
            {
                peoplelist = Load_OutFile.QueryData("person", "name", "name =" + "'" + colname + "'");
                if(peoplelist.Count==1)
                {
                    label_message.Text = "查询到一个";
                }
                else if(peoplelist.Count>1)
                {
                    label_message.Text = "查询到" + peoplelist.Count.ToString() + "个，\r\n请选择";
                    datelist= Load_OutFile.QueryData("person","telnumber","name=" + "'" + colname + "'");
                    foreach(string date in datelist)
                    {
                        comboBox_date.Items.Add(date);
                    }
                }
            }
            
        }

        private void comboBox_date_TextChanged(object sender, EventArgs e)
        {
            
            peopleInfo= Load_OutFile.CmdQuery(" SELECT * FROM person WHERE name='"+textBox_name.Text.Trim()+"'"+"AND telnumber='"+
                comboBox_date.Text.Trim()+"'");
            
            medicineList = Load_OutFile.CmdQuery("SELECT drugName FROM medicineList WHERE telnumber='" + comboBox_date.Text.Trim() +
                "'");
            dosageList= Load_OutFile.CmdQuery("SELECT dosage FROM medicineList WHERE telnumber='" + comboBox_date.Text.Trim() +
                "'");
            number =Load_OutFile.CmdQuery("SELECT number FROM medicineList WHERE telnumber = '" + comboBox_date.Text.Trim() +
                "'");
            //EventArgs eventArgs = new EventArgs();
            if (ComboBoxTextChanged!=null)ComboBoxTextChanged(sender, e);
        }
    }
}
